/**
 * @author : dormi330
 * @date : 2020-03-20
 * description : 文件描述
 */

package org.dormi.learn;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class StreamAPI {

    public static void main(String[] args) {

        stream_filter_1(3);
        stream_filter_1(5);

        stream_anyMatch(1);
        stream_anyMatch(10);
    }

    public static void printList(List l) {
        l.forEach(e -> System.out.println(e));
    }

    private static void stream_filter_1(int x) {
        printMethodName();
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5)
                .parallelStream()
                .filter(e -> e > x)
                .collect(Collectors.toList());
        printList(list);
    }


    private static void stream_anyMatch(Integer x) {
        printMethodName();
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);

        Integer r = list.parallelStream()
                .filter(e -> e > x)
                .findAny()
                .orElse(null);

        System.out.println(r);
    }

    private static void printMethodName() {
        String nameofCurrMethod = new Throwable()
                .getStackTrace()[1]
                .getMethodName();

        System.out.println("execute : " + nameofCurrMethod);

    }
}
